package temp_test;

import java.io.*;

/**
 * 客户端
 * 
 * @author AfritXia
 *
 */
public class ClientTest {
	/**
	 * 输入流
	 * 
	 */
	private BufferedReader _br = null;
	
	/**
	 * 类默认构造器
	 * 
	 */
	public ClientTest() {
	}

	/**
	 * 启动客户端
	 * 
	 */
	public void startUp() {
		// 创建服务器端
		ServerProxy theServer = new ServerProxy();
		
		System.out.println(theServer.getPostedString());

		// 启动线程
//		(new Thread(theServer)).start();
		
		while (true) {
			// 读取一行
			String newln = this.readLine();
			// 令服务器端接收文本
			theServer.receiveString(newln);
		}
	}

	/**
	 * 获取输入流
	 * 
	 * @return 
	 * 
	 */
	private BufferedReader getBufferedReader() {
		if (this._br == null) {
			try {
				// 创建输入流
				this._br = new BufferedReader(new InputStreamReader(System.in));
			} catch (Exception ex) {
				// 抛出异常
				throw new RuntimeException(ex);
			}
		}

		return this._br;
	}

	/**
	 * 读取行文本
	 * 
	 * @return
	 * 
	 */
	private String readLine() {
		try {
			// 读取行文本
			return this.getBufferedReader().readLine();
		} catch (Exception ex) {
			// 抛出异常
			throw new RuntimeException(ex);
		}
	}

	/**
	 * 应用程序主函数
	 * 
	 * @param args
	 * 
	 */
	public static void main(String[] args) {
		(new ClientTest()).startUp();
	}
}
